package com.zjq.control;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;

import com.zjq.service.LoginService;
import com.zjq.service.QingJiaService;

@RequestMapping("/qj")
@Controller
public class QingJia {
	@Autowired
	private LoginService login;
	@Autowired
	private QingJiaService qjs;
	@RequestMapping(value="write", params={"name","teacher","context","begintime","endtime"})
	public String write(@RequestParam("name") String name,
			@RequestParam("teacher") String teacher,
			@RequestParam("context") String context,
			@RequestParam("begintime") String begintime,
			@RequestParam("endtime") String endtime){
		if (qjs.write(name, teacher, context, begintime, endtime)) {
			return "redirect:/user/first?name="+name+"&type=0";
		}
		return "fail";
	}
	@RequestMapping(value="tsp", params={"name","id","yesorno","next"})
	public String teacherShenpi(@RequestParam("name") String name,
								@RequestParam("yesorno") Integer yesorno,
								@RequestParam("id") Integer id,
								@RequestParam("next")String next){
		if (qjs.Shenpi(name, yesorno, id, next)) {
			return "redirect:/user/first?name="+name+"&type=1";
		}
		return "fail";
	}
	@RequestMapping(value="login", params={"type","name","pwd"})
	public String login(@RequestParam("type") int type,
						@RequestParam("name") String name,
						@RequestParam("pwd") String pwd){
		try {
				return "redirect:/user/first?name="+name+"&level="+login.login(name);
		} catch (Exception e) {
			// TODO: handle exception

			e.printStackTrace();
		}
		return "fail";
	}
}
